package com.softmaker.service;

import com.softmaker.entity.MangerInfo;
import com.softmaker.entity.UserInfo;
import com.softmaker.repository.MangerInfoRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.List;
import java.util.UUID;

@Service
public class MangerInfoService {
    @Autowired
    private MangerInfoRepository repository;

    public MangerInfo addManger(MangerInfo mangerInfo) {
        mangerInfo.setMangerId(UUID.randomUUID().toString());
        return repository.save(mangerInfo);
    }
    public MangerInfo findManger(MangerInfo mangerInfo){
        return repository.findMangerInfoByMangerName(mangerInfo.getMangerName());
    }
    @Transactional
    public void deleteMangerInfoByMangerName(String mangerName){
        repository.deleteMangerInfoByMangerName(mangerName);
    }
    @Transactional
    public MangerInfo updatePasswordByMangerName(MangerInfo mangerInfo){
        repository.updatePasswordByMangerName(mangerInfo.getPassword(), mangerInfo.getMangerName());

        return repository.findByMangerName(mangerInfo.getMangerName());
    }
    public List<MangerInfo> listManger(){
        return repository.findAll();
    }
}
